/**
 * Created by zhong on 2018/1/24.
 */
import axios from "axios"
import config from "../util/api.config"
axios.defaults.baseURL = config.url;

let win = typeof window
let isClient = false
if(win && win != 'undefined'){
  isClient = true
}
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  // 在发送请求之前加toke
  let xtoken = isClient ? localStorage.token : null;
  if(xtoken != null){
    config.headers['authorization'] = xtoken
  }
  return config;
}, function (error) {
  // 请求错误
  return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 响应数据基本判断
  // 对token过期的跳转登录页面
  if (response.data.code == 510100){

  }
  return response;
}, function (err) {
  return Promise.reject(err);
})

const api = axios

export default api
